The Hodrick-Prescott Filter

Macroeconomics (M8674)

February 2026


Vivaldo Mendes, ISCTE
vivaldo.mendes@iscte-iul.pt

1. Main goal

Main goal of a filter in macroeconomics

  • In economics, any filter intends to separate a time-series into a trend and a cyclical component such that:

    • The trend is the long-run component of the time series
    • The cyclical component is the short-run component of the time series
  • Therefore, from (1) we get

  • The trick is to minimize eq. (2) subject to some given constraint on

Types of Filters


  • There are various approaches to separate the long-run trend from the short-run cyclical component of a time series .
    • Linear filter
    • Linear filter with breaks
    • Nonlinear filters
  • Nonlinear filters

Don't trust the internet or chatbots

  • If you do not know what you are doing, you will make stupid mistakes

  • The internet is full of wrong (or incomplete) information

  • Even very respected sources may mislead you:

    • Stata may mislead you: here
    • Statsmodels (a famous Python library) may mislead you: here
    • R may mislead you: here
    • Matlab may mislead you: here
  • Either you know very well what you are doing, or ...

2. The Hodrick-Prescott filter (HP)

The HP filter: some intuition


  • We have some data: a time series
  • We want to extract a smooth trend from
  • We want the difference between the two , to be "acceptable" given what we know about booms and recessions: not too large, not too small
  • We introduce a parameter () into a minimization problem to achieve that
  • The minimization problem with respect to can be written as:

The HP filter: Special Cases


The value given to parameter is a choice of ours:


  • trivial solution because there are no cycles :
  • linear trend leads to huge cycles between and
  • duration/amplitude of cycles acceptable for quarterly data
  • duration/amplitude of cycles acceptable for annual data
  • There is no "unquestionable" value for

The HP Filter: an Example


  • Main objective: obtain cycles as % deviations from the trend
  • This has an important implication:
    • Time series with a trend: apply logs to the data before extracting the trend and the cycles (lnGDP, lnCPI)
    • Time series without a clear trend: do not apply logs to the data (UR)
  • Quarterly data: US_data.csv
  • A simple example:
    • Real GDP (column GDP)
    • Consumer Price Index (column CPI)
    • Unemployment Rate (column UR)

Dealing with rows and columns in a matrix


Dealing with rows and columns in a dataframe


To select a column:

  • Use its header (GDP in the example)
  • It is also possible to use its column number (not shown here)

To select rows:

  • Use their numbers (1, 2, 3, ...)
  • Range of numbers (1:4 in the example)
  • No number, just the header: all rows are selected
  • Use a condition (e.g. USdata[USdata.CPI .< 0 , :])

Compute the HP trend and cycles: a single variable


Compute the HP trend and cycles: an entire data set


Business cycles: Inflation and Unemployment


The inflation-gap The unemployment-gap

The output-gap: logs vs levels


Correctly measured: using logs Incorrectly measured: using levels

3. Use filters with care

Three Major Issues


  • There is no perfect filter ... but the HP seems very good.
  • Measuring Potential GDP and Natural Unemployment is difficult:
    • Potential GDP is usually associated with the HP-trend in GDP ... but not exclusively.
    • The Natural Rate of Unemployment is largely associated with the HP-trend in unemployment.
  • The HP filter can be misused for policy purposes:
    • The James Bullard 2012 case in the USA is a well-known example.
  • The HP filter is very useful but should be used with care.

Limitations of the HP Filter


  • New data leads to the rewriting of the history of the economy
  • The blue lines: data only up to 2008
  • The red lines: data up to 2013

| | |

Misuses of the HP Filter


  • In 2012, the US economy had an unemployment rate close to 8%, one of the highest rates since WWII.
  • The Fed Funds Rate was at 0%, to stimulate the economy.
  • The inflation rate was much below the target level (2%) at 0.5% and showing signs of going down.

  • James Bullard (the President of the Fed of St. Louis), in a famous speech in June 2012 defended that the US economy had gone back to Potential GDP.
    • He strongly pushed for a sharp increase in the Fed Funds Rate.
    • He used the HP-filter to substantiate his proposal.

The HP filter according to James Bullard


The Output-gap according to the Fed of St. Louis


  • The Fed of St. Louis publishes "oficial" US data for Real GDP and Potential GDP.
  • Real GDP is the blue line; Potential GDP is the red line.

HP filter & the Natural Unemployment Rate (NUR)


No, Covid-19 did not raise the NUR; no, an increase in NUR did not anticipate Covid-19!

Appendix: HP Filter Derivation

Not compulsory reading

Minimization of the Loss function


The loss function is given by:

To minimize the Loss function with respect to :

Take the derivatives with respect to and setting them to zero:

Those derivatives are known as the First Order Conditions (FOCs).

First Order Conditions (FOCs)

  • For

  • For

First Order Conditions (FOCs): continuation

  • For , such that , the FOC is given by:


    • or
  • And for the two right boundary conditions , we have the following FOCs (they are symmetric to those on the left boundary)

First Order Conditions (FOCs): Matrix form

The 5 FOCS that represent the optimal conditions on the left boundary, the right boundary, and the interior conditions are:


So, we can write:

An example with n=6



An example with n=6 (cont.)



An example with n=6 (cont.)


  • This is not a viable way to writing down the Lagrangian function to minimize the problem because is not an interior index, as we have only 6 observations.
  • We have to apply the boundary condition that the number of observations end at
  • Then we will move backward to .
  • When we get the results for and , the entire solution set is known.

An example with n=6 (cont.)


At the initial boundary we iterate forward, at the end boundary we iterate backwards

An example with n=6: all FOCs






An example with n=6


  • If n = 6, the dense form of A is given by:

  • Notice the symmetry of matrix A
    • .
    • ,
    • ,

Notebook implementation

  • Matrix A non-trivial diagonals:

    • .
    • ,
    • ,
    • ,
    • .

  • Check the function hp_trend in the notebook HP_IRF_2026.jl

4. Readings

Point 2

  • For this point, there is no compulsory reading.

  • However, Dirk Krueger (2007). "Quantitative Macroeconomics: An Introduction" (Chapter 2), manuscript, Department of Economics University of Pennsylvania, is well suited for the material covered here.

  • This text is a small one (12 pages), easy to read, and beneficial for studying the stylized facts of business cycles, mainly to understand how the Hodrick-Prescott filter is calculated. However, notice that, as mentioned, it is not compulsory reading.

Point 3

  • No textbook covers the topics/controversies mentioned in this section.
  • This coursework intends to provide a framework for a better understanding of these controversies at the end of the course.
  • All we have to handle is:
    • A little bit of mathematics
    • A little bit of computation
    • A little bit of macroeconomics